﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Fuyao.Business.Entities.Models;
using System.Data.Common;

namespace Fuyao.Data.SQLServer.DAO
{
    public class DAOMenuXPerfil
    {
        string strCnx = clsConexionDB.getConexionSQL();

        //Principal
        public List<MenuXPerfil> getMenuXPerfil(int? perfilID)
        {

            MenuXPerfil oMenuXPerfil = null;
            StringBuilder strCommand = new StringBuilder();
            SqlConnection cnx = new SqlConnection(strCnx);
            List<MenuXPerfil> listMenuXPerfil = new List<MenuXPerfil>();
            try
            {
                strCommand.Append("SELECT MenuID, PerfilID ");
                strCommand.Append("FROM MenuXPerfil WHERE PerfilID = @PerfilID ");

                SqlCommand sqlCommand = new SqlCommand(strCommand.ToString(), cnx);

                sqlCommand.Parameters.Add("@PerfilID", SqlDbType.Int).Value = perfilID;

                cnx.Open();
                SqlDataReader dr = sqlCommand.ExecuteReader();

                while (dr.Read())
                {
                    oMenuXPerfil = new MenuXPerfil();

                    if (!Convert.IsDBNull(dr["MenuID"])) oMenuXPerfil.MenuID = Convert.ToInt32(dr["MenuID"]);
                    if (!Convert.IsDBNull(dr["PerfilID"])) oMenuXPerfil.PerfilID = Convert.ToInt32(dr["PerfilID"]);
                    listMenuXPerfil.Add(oMenuXPerfil);
                }

                dr.Close();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                cnx.Close();
            }
            return listMenuXPerfil;
        }
    }
}
